package com.leyou.cat.listener;

import com.leyou.cat.service.CartService;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author zqq
 * @ClassName CartListener
 * @Description
 * @date 2020/4/10-9:21
 */
@Component
public class CartListener {

    @Autowired
    private CartService cartService;

    /**
     * 处理订单创建后，清除购物车中数据
     *
     * @param params
     * @throws Exception
     */
    @RabbitListener(bindings = @QueueBinding(
            value = @Queue(value = "leyou.clear.cart.queue", durable = "true"),
            exchange = @Exchange(
                    value = "leyou.cart.exchange",
                    ignoreDeclarationExceptions = "true",
                    type = ExchangeTypes.TOPIC),
            key = {"cart.clear"}))
    public void listenCreate(Map<String,Object> params) throws Exception {
        if (params == null || params.size() == 0) {
            return;
        }
        cartService.clearCart(params);
    }
}
